package org.skipper.samples.redission.set;

import org.redisson.api.RedissonClient;
import org.skipper.samples.redission.enums.RedisKeyEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2021-08-27
 * Time: 下午6:01
 */
@Component
public class SetSource {

    @Resource
    @Qualifier(value = "redis-cloud_0")
    private RedissonClient redissonClient;

    public void sadd() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).add("test");
    }

    public void scard() {
        int count = redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).size();
        System.out.println("count = " + count);
    }

    public void sismember() {
        boolean contains = redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).contains("test");
        System.out.println("contains = " + contains);
    }

    public void sinterstore() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).intersection("test");
    }

    public void sinter() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).readIntersection("test");
    }

    public void smembers() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).readAll();
    }

    public void smove() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).remove("test");
    }

    public void spop() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).removeRandom();
    }

    public void srem() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).remove("test");
    }

    public void sunion() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).readUnion("test");
    }

    public void sunionstore() {
        redissonClient.getSet(RedisKeyEnum.SET_TEST.getCode()).union("test");
    }



}
